import { fromJS } from "immutable";
import * as constants from "./constants";

const defaultState = fromJS({
  topicList: [],
  articleList: [],
  recommendList: [],
  page: 1,
  showScroll: false,
});
export default function homeReducer(state = defaultState, action) {
  const { type, data, flag, page } = action;
  console.log(data);
  switch (type) {
    case constants.CHANGE_HOME_DATA:
      console.log(data);
      return state.merge({
        topicList: fromJS(data.topicList),
        articleList: fromJS(data.articleList),
        recommendList: fromJS(data.recommendList),
      });
    case constants.ADD_ARTICLE_LIST:
      return state.merge({
        articleList: state.get("articleList").concat(fromJS(data)),

        page: page,
      });
    case constants.TOGGLE_SCROLL_TOP:
      return state.set("showScroll", flag);

    default:
      return state;
  }
}
